<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="../assets/lib/NProgress/NProgress.css" />
    <link rel="stylesheet" href="../assets/lib/toastr/toastr.min.css" />
  </head>
  <body>
    <script src="../assets/lib/axios.js"></script>
    <script src="../assets/lib/NProgress/NProgress.js"></script>
    <script src="../assets/lib/jquery-3.6.0.min.js"></script>
    <script src="../assets/lib/toastr/toastr.min.js"></script>
    <script>
      axios.interceptors.request.use(
        function (config) {
          NProgress.start(); // 显示加载中
          return config;
        },
        function (error) {
          return Promise.reject(error);
        }
      );

      axios.interceptors.response.use(
        function (response) {
          NProgress.done(); // 关闭加载中
          console.log();
          if (response.data.code !== 0) {
            toastr.error(response.data.message);
          } else {
            toastr.success(response.data.message);
          }

          return response;
        },
        function (error) {
          NProgress.done(); // 关闭加载中
          console.dir(error);
          toastr.error(error.data.message);
          return Promise.reject(error);
        }
      );
      //获取数据
      axios({
        url: "http://www.itcbc.com:8000/api/login",
        method: "post",
        data: {
          username: "admin123",
          password: "admin123",
        },
      }).then((result) => {
        //result 返回的是 return response;   的结果
        console.log(result);
      });
    </script>
  </body>
</html>
